package com.ms.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ms.domain.dto.ReviewDTO;
import com.ms.domain.entity.Music;
import com.ms.result.Result;
import com.ms.service.AuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/audit")
@Tag(name = "B端审核相关接口")
@RequiredArgsConstructor
@Slf4j
public class AuditController {
    private final AuditService auditService;

    @GetMapping("/pending")
    @Operation(summary = "获取待审核的音乐列表")
    public Result<Page<Music>> getPendingMusic(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return Result.success(auditService.getPendingMusic(page, size));
    }

    @PostMapping("/review")
    @Operation(summary = "审核音乐")
    public Result<Void> reviewMusic(@RequestBody @Valid ReviewDTO dto) {
        try {
            auditService.reviewMusic(dto);
            return Result.success();
        } catch (Exception e) {
            return Result.badRequest(e.getMessage());
        }
    }
}